import 'package:flutter/material.dart';
import 'package:flutter_4/screen/Home.dart';
import 'package:flutter_4/screen/LoginScreen.dart';
import 'package:flutter_4/screen/RegisterPage.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_4/News.dart';
import 'package:oktoast/oktoast.dart';
import 'dart:convert';
import 'NewsDetail.dart';
import 'package:sqflite/sqflite.dart';
// import 'package:fluttertoast/fluttertoast.dart/';
import 'package:path/path.dart';
import 'package:flutter_4/database.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {

    return OKToast(
        position: ToastPosition.bottom,
        backgroundColor: Color(0xFFB2B2B2),
        child: new MaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'Flutter Demo',
          theme: new ThemeData(
            primarySwatch: Colors.blue,
          ),
          routes: {
            /**
             * 命名导航路由，启动程序默认打开的是以'/'对应的界面LoginScreen()
             * 凡是后面使用Navigator.of(context).pushNamed('/Home')，都会跳转到Home()，
             */
            '/': (BuildContext context) => new LoginScreen(),
            '/Home': (BuildContext context) => new Home(),
            '/register':(BuildContext context) => new RegisterPageUI(),
            '/login':(BuildContext context) => new LoginScreen()
          },
        )
    );
  }
}

Future<List<News>> getDates() async{
  final response = await http.get(Uri.parse(
      'http://api.tianapi.com/generalnews/index?key=003d0726b05eec927021ad13dab02d7e'
  ));
  Utf8Decoder decode=new Utf8Decoder();
  Map<String,dynamic>result=jsonDecode(decode.convert(response.bodyBytes));
  List<News>datas;
  datas=result['newslist'].map<News>((item)=>News.fromJson(item)).toList();
  return datas;
}